<%@ page import="java.sql.*" %><%--
  Created by IntelliJ IDEA.
  User: lenovo
  Date: 2018/4/15
  Time: 19:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>查询</title>
</head>
<body>
<a href="userList.jsp">返回列表</a>
<form>
    name:<input type="text" name="name"/></br>
    <input type="submit" value="查询"/>
</form>
<%
    String namevalue = request.getParameter("name");

    if (namevalue == null) {
        out.print("<p>请输入你的名字.</p>");
    } else {
        Connection connection = null;
        Statement statement = null;

        try {
            Class.forName("com.mysql.cj.jdbc.Driver");

            connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/sctu_javaweb_2018?serverTimezone = UTC && characterEncoding = UTF-8", "root", "193749");

            statement = connection.createStatement();

            ResultSet resultSet = null;
            resultSet = statement.executeQuery("SELECT * FROM t_users WHERE  username = '" + namevalue + "';");

            //定义变量进行是否有此人的判断
            boolean bool = true;

            while (resultSet.next()) {
                out.print("<p>基本信息" + "   id:" + resultSet.getString(1) + "  name:" + resultSet.getString(2) + "  password:" + resultSet.getString(3) + "</p>");
                bool = false;
            }

            if (bool == true) {
                out.print("暂无此人信息.");
            }


        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        } catch (SQLException e) {
            e.printStackTrace();
        } finally {
            try {
                connection.close();
                statement.close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
    }
%>
</body>
</html>

